import { defineStore } from "pinia";
import { reqC1,reqC2,reqC3,reqAttrList} from "@/api/product/attr";
import type { CategoryrResponseData ,AttrResponseData} from "@/api/product/attr/type";
import type { CategoryState } from "./types/type";
const useCategoryStore = defineStore('Category', {
    state: (): CategoryState => {
        return {
            C1Arr: [],
            C1ID: '',
            C2Arr:[],
            C2ID:'',
            C3Arr:[],
            C3ID:'',
            AttrList:[]
        }
    },
    actions: {
        async getC1() {
            const result: CategoryrResponseData = await reqC1();
            if (result.code == 200) {
                this.C1Arr = result.data;
            }
        },
        async getC2(){
            const result: CategoryrResponseData = await reqC2(this.C1ID);
            if (result.code == 200) {
                this.C2Arr = result.data;
            }
        },
        async getC3(){
            const result: CategoryrResponseData = await reqC3(this.C2ID);
            if (result.code == 200) {
                this.C3Arr = result.data;
            }
        },
        async getAttr(){
            const result: AttrResponseData = await reqAttrList(this.C1ID,this.C2ID,this.C3ID);
            if (result.code == 200) {
                this.AttrList = result.data;
            }
        },
    }
})
export default useCategoryStore;